/* inxml.h is part of VIP program
 * Written by J. Salvador Arias, 2010
 *      CONICET, INSUE, Instituto Miguel Lillo,
 *      Miguel Lillo 205, S.M. de Tucuman (4000)
 *      Tucuman, Argentina
 *      e-mail: jsalarias@csnat.unt.edu.ar
 *
 * VIP is a free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation and
 * Creative Commons.
 *
 * This file and the VIP program is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * To view a copy of this license, visit
 * http://creativecommons.org/licenses/GPL/2.0/
 * or send a letter to
 * Creative Commons, 171 Second Street, Suite 300,
 * San Francisco, California, 94105, USA.
 */

#ifndef INPUT_STREAM_FOR_KML_LIKE_FILES_HEADER_INCLUDED
#define INPUT_STREAM_FOR_KML_LIKE_FILES_HEADER_INCLUDED

/* ------ xml file reading ------ */
/* Functions to parse and read a sub-set of XML files, used as input */

#include "ghead.h"
#include "in.h"

#define XML_ERROR           0x0000
#define XML_TOKEN_OPEN      0x0001
#define XML_TOKEN_CLOSE     0x0002
#define XML_TOKEN_COMMENT   0x0004
#define XML_TOKEN_CONTENT   0x0008
#define XML_TOKEN_CDATA     0x0010
#define XML_TOKEN_NOCONTENT 0x0020
#define XML_TOKEN_EMPTY     0x0040
#define XML_WITH_PARAMS     0x0100
#define XML_NO_PARAMS       0x0200
#define XML_AUTO_CLOSE      0x0400

typedef struct tagXMLPARSER XMLPARSER;

/* Reading the XML input */
SFLAG IsXMLFile (INSTREAM* in);
SFLAG ReadToken (INSTREAM* in, GString* dest, SFLAG* tokenState);
SFLAG ReadXMLTokenParam (INSTREAM* in, GString* paramName, GString* paramVal, SFLAG* tokenState);
SFLAG ReadXMLContent (INSTREAM* in, GString* dest, SFLAG* textState);

SFLAG SkipParams (INSTREAM* in);

SFLAG ReadXMLFile (XMLPARSER* xmlParser);

void RemoveFromTokenList (XMLPARSER* xmlParser);
SFLAG IgnoreOpenTag (XMLPARSER* xmlParser);
GString* GetPrevToken (XMLPARSER* xmlParser);
void CleanTokenStack (GList* toClean);

/* Definitions */

struct tagXMLPARSER {
 SFLAG (*OpenTag) ();
 SFLAG (*EndTag) ();
 SFLAG (*OnError) ();

 GString* tempParserString;
 INSTREAM* in;
 gchar* fileHeader;
 GList* tokenStack;
 SFLAG tokenState;
};

#endif
